package com.ruoyi.socket.screen;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.gams.domain.GamsUserQueue;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class ScreenVO
{
    private Integer id;

    /**
     * 用户姓名
     */
    private String userName;

    /**
     * 业务名称
     */
    private String bussinessName;

    /**
     * 状态：1.取号 2.业务办理中 3.挂起 4.办理结束 9.过号
     */
    private String statusStr;

    /**
     * 排队号码
     */
    private String number;

    private String windowName;

    /**
     * 创建时间
     */
    private String createTime;


    public static List<ScreenVO> userQueueList2ScreenVOList2(List<GamsUserQueue> list)
    {
        List<ScreenVO> result = new ArrayList<>();
        for (int i = 0; i < list.size(); i++)
        {
            GamsUserQueue gamsUserQueue = list.get(i);
            ScreenVO screenVO = userQueue2ScreenVO2(gamsUserQueue, i);
            result.add(screenVO);
        }
        return result;
    }

    public static ScreenVO userQueue2ScreenVO2(GamsUserQueue queue, int i)
    {
        ScreenVO screenVO = new ScreenVO();
        screenVO.setBussinessName(queue.getBussinessName());
        screenVO.setCreateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, queue.getCreateTime()));
        screenVO.setNumber(queue.getNumber());
        screenVO.setStatusStr(getStatusStr(queue.getStatus()));
        screenVO.setUserName(getName(queue.getUserName()));
        screenVO.setId(i + 1);
        screenVO.setWindowName(queue.getWindowNum());
        return screenVO;
    }

    //隐藏一个字
    public static String getName(String sourceName)
    {
        if (StringUtils.isEmpty(sourceName))
        {
            return "";
        }
        if (sourceName.length() > 2)
        {
            return sourceName.substring(0, 1) + "*" + sourceName.substring(2, 3);
        }
        else
        {
            return sourceName.substring(0, 1) + "*";
        }
    }

    //状态转中文
    public static String getStatusStr(Integer status)
    {
        switch (status)
        {
            case 1:
                return "排队中";
            case 2:
                return "办理中";
            case 3:
                return "挂起中";
            case 4:
                return "完成";
            default:
                return "其他";
        }
    }

}
